<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla controlleradmin library
jimport('joomla.application.component.controlleradmin');

/**
 * Products Controller
 */
class ProductControllerProducts extends JControllerAdmin
{
	/**
	 * Constructor.
	 *
	 * @param	array	$config	An optional associative array of configuration settings.
	
	 * @return	ProductControllerProducts
	 * @see		JController
	 */
	public function __construct($config = array())
	{
		parent::__construct($config);
	
		$this->registerTask('unfeatured', 'featured');
	}
	
	
	/**
	 * Proxy for getModel.
	 */
	public function getModel($name = 'Product', $prefix = 'ProductModel')
	{
		$model = parent::getModel($name, $prefix, array('ignore_request' => true));
		return $model;
	}
	
	/**
	 * Method to toggle the featured setting of a list of product.
	 */
	function featured()
	{
		// Check for request forgeries
		JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
	
		// Initialise variables.
		$user	= JFactory::getUser();
		$ids	= JRequest::getVar('cid', array(), '', 'array');
		$values	= array('featured' => 1, 'unfeatured' => 0);
		$task	= $this->getTask();
		$value	= JArrayHelper::getValue($values, $task, 0, 'int');
	
		// Get the model.
		$model = $this->getModel('products');
		
		// Publish the items.
		if (!$model->featured($ids, $value)) {
			JError::raiseWarning(500, $model->getError());
		} else {
			// TODO Raise success message here
			// JFactory::getApplication()->enqueueMessage(JText::_('SUCCESS'));
		}
	
		$this->setRedirect('index.php?option=com_product&view=products');
	}
}